using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.Windows.Forms;
using System.Xml.Schema;
using System.IO;
using System.Drawing;
using OpenComposite.Base;
using OpenComposite.Repository.Properties;

namespace OpenComposite.EII.Repository
{
	[RepositoryItem(ItemType.KPI_Function, "kpi_functions", "function_id")]
	public class KPIFunction : RepositoryItemBase
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="KPIFunction"/> class.
		/// </summary>
		public KPIFunction()
			: base("function_id", "function_nm", "function_desc", "function_ntext", Resources.sNewKPIFunction)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="KPIFunction"/> class.
		/// </summary>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public KPIFunction(bool bCreateNew)
			: this()
		{
			if ( bCreateNew )
				this.CreateNew();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="KPIFunction"/> class.
		/// </summary>
		/// <param name="id">The id.</param>
		public KPIFunction(int id)
			: this()
		{
			this.Load(id);
		}
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the code.
		/// </summary>
		/// <value>The code.</value>
		public string Code
		{
			get { return getString("function_code", ""); }
			set { setValue("Code", "function_code", value); }
		}
		/// <summary>
		/// Gets or sets the metric ID.
		/// </summary>
		/// <value>The metric ID.</value>
		public int MetricID
		{
			get { return getInt("metric_id", -1); }
			set { setValue("MetricID", "metric_id", value); }
		}

		#endregion

		#region Methods

		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			KPIFunction copy = new KPIFunction(true);
			copy.InitializeServiceProvider(this);
			this.CopyDataRowToTarget(copy);
			return copy;
		}

		#endregion

		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override Image Image
		{
			get { return Resources.policy; }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.KPI_Function; }
		}
		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return "KPI Function"; }
		}
		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "kpi_functions"; }
		}
		private static List<ItemType> _LISTALLOWED = new List<ItemType>(new ItemType[] { ItemType.KPI_Schedule });
		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return _LISTALLOWED; }
		}


		/// <summary>
		/// Gets the display text.
		/// </summary>
		/// <value>The display text.</value>
		public override string Display
		{
			get
			{
				return this.Name;
			}
		}

		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override Image SelectedImage
		{
			get { return this.Image; }
		}

		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "policy"; }
		}

		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return this.ImageKey; }
		}

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override Icon GetIcon()
		{
			Bitmap bmp = new Bitmap(this.Image);
			bmp.MakeTransparent(Color.Magenta);
			return Icon.FromHandle(bmp.GetHicon());
		}

		/// <summary>
		/// Sets the default values.
		/// </summary>
		protected override void SetDefaultValues()
		{
			this.Code = "";
			this.MetricID = -1;
			base.SetDefaultValues();
		}

	}
}